package com.syezon.wifikey.enhance;

import android.app.Application;
import android.arch.lifecycle.AndroidViewModel;
import android.arch.lifecycle.MutableLiveData;
import android.support.annotation.NonNull;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 齐超波 on 2018/9/16.
 */

public class EnhanceViewModel extends AndroidViewModel {

    private MutableLiveData<List<EnhanceItemInfo>> enhanceLiveData = new MutableLiveData<>();
    private MutableLiveData<Boolean> enhanceFinishLiveData = new MutableLiveData<>();


    public EnhanceViewModel(@NonNull Application application) {
        super(application);
    }

    public MutableLiveData<List<EnhanceItemInfo>> getEnhanceLiveData(){
        return enhanceLiveData;
    }

    public MutableLiveData<Boolean> getEnhanceFinishLiveData() {
        return enhanceFinishLiveData;
    }

    public void startEnhance(){
       new Thread(){
           @Override
           public void run() {
               List<EnhanceItemInfo> enhanceItemInfos = new ArrayList<>();
               EnhanceItemInfo wifiTestTitle = new EnhanceItemInfo();
               wifiTestTitle.setType(EnhanceItemInfo.TYPE_HARD);
               wifiTestTitle.setTitle("硬件升级");
               wifiTestTitle.setTotal(3);
               wifiTestTitle.setFinish(false);
               wifiTestTitle.setEnhanceList(getHardList());
               enhanceItemInfos.add(wifiTestTitle);
               enhanceLiveData.postValue(enhanceItemInfos);
               pause(2000);
               wifiTestTitle.setFinish(true);
               enhanceLiveData.postValue(enhanceItemInfos);

               EnhanceItemInfo dividerItem = new EnhanceItemInfo();
               dividerItem.setType(EnhanceItemInfo.TYPE_DIVIDER);
               enhanceItemInfos.add(dividerItem);

               EnhanceItemInfo wifiOptItem = new EnhanceItemInfo();
               wifiOptItem.setType(EnhanceItemInfo.TYPE_HARD);
               wifiOptItem.setTitle("WiFi优化");
               wifiOptItem.setTotal(3);
               wifiOptItem.setFinish(false);
               wifiOptItem.setEnhanceList(getWifiOptList());
               enhanceItemInfos.add(wifiOptItem);
               enhanceLiveData.postValue(enhanceItemInfos);
               pause(2000);
               wifiOptItem.setFinish(true);
               enhanceLiveData.postValue(enhanceItemInfos);
               enhanceFinishLiveData.postValue(true);
           }
       }.start();
    }

    private void pause(long time){
        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public List<String> getHardList (){
        List<String> list = new ArrayList<>();
        list.add("优化无线模块内核，提高速度");
        list.add("低信号下保持连接，不断线");
        list.add("减少延迟，提升网络稳定，减少网络丢包");
        return list;
    }

    public List<String> getWifiOptList (){
        List<String> list = new ArrayList<>();
        list.add("优化WiFil连接引擎");
        list.add("优化无线网络多线程");
        list.add("减少延迟，提升网络稳定，减少网络丢包");
        list.add("优化WiFi网络选择");
        list.add("优化Host/DNS域服务器");
        list.add("智能调整WAN模式");

        return list;
    }

}
